home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / lang_ext / vbawk / entab.usr < prev    next >
Encoding:
Text File  |  1994-08-14  |  2.4 KB  |  89 lines

  1. Global Const HIGHEST_TAB = 100
  2. Global TabStops(-1 To HIGHEST_TAB) As Integer    'tab stops array
  3. Global NumTabStops As Integer      'number of tab stops in array
  4.  
  5. Const FOUND_TAB = 1
  6. Const NO_TAB = 2
  7.  
  8. 'This routine is called after each file is closed and
  9. 'all processing for that file is finished.
  10. Sub AfterAFile ()
  11. End Sub
  12.  
  13. 'This routine is called at the very end of the program,
  14. 'after all files have been processed.
  15. Sub AfterAllFiles ()
  16. End Sub
  17.  
  18. 'The return value of BeforeAFile is usually True, which
  19. 'indicates that the current file is to be processed
  20. 'normally.  By returning False, you can skip processing
  21. 'the current file.
  22. Function BeforeAFile ()
  23.     BeforeAFile = True
  24. End Function
  25.  
  26. 'This routine is executed at the very beginning of the
  27. 'application, before any files are opened or any
  28. 'processing has taken place.
  29. Function BeforeAllFiles () As Integer
  30.     APPNAME = "MS-Windows Entabbing Utility"
  31.     TabStops(-1) = 1
  32.     SetTabStops.Show 1
  33.     If SetTabStops.Tag = "CANCEL" Then
  34.     BeforeAllFiles = False
  35.     Else
  36.     BeforeAllFiles = True
  37.     End If
  38. End Function
  39.  
  40. Sub CountBlanks (NumBlanks%, Flag%, ByVal i%, TheLine$, t%)
  41.     NumBlanks% = 0
  42.     While Mid$(TheLine$, i%, 1) = " " And i% < TabStops(t%)
  43.     NumBlanks% = NumBlanks% + 1
  44.     i% = i% + 1
  45.     Wend
  46.     If i% = TabStops(t%) Then
  47.     Flag% = FOUND_TAB
  48.     Else
  49.     Flag% = NO_TAB
  50.     End If
  51. End Sub
  52.  
  53. 'This routine called over and over, each time being
  54. 'passed a succeeding line of the file being
  55. 'processed.  Or, in binary mode, this routine is passed
  56. 'a chunk of bytes as long as RECLEN, except for the
  57. 'final chunk which may be smaller than RECLEN.
  58. Function DoALine (TheLine As String) As Integer
  59.     i% = 1  'pointer to the original string
  60.     t% = 0  'index into tabstops array
  61.     TheChar$ = Mid$(TheLine, i%, 1)
  62.     While TheChar$ <> ""
  63.     If TheChar$ = " " Then
  64.         CountBlanks NumBlanks%, Flag%, i%, TheLine, t%
  65.         If Flag% = FOUND_TAB And NumBlanks% > 1 Then
  66.         TheChar$ = Chr$(9)
  67.         i% = i% + NumBlanks%
  68.         Else
  69.         i% = i% + 1
  70.         End If
  71.         NewLine$ = NewLine$ & TheChar$
  72.     Else
  73.         NewLine$ = NewLine$ & TheChar$
  74.         i% = i% + 1
  75.     End If
  76.     TheChar$ = Mid$(TheLine, i%, 1)
  77.  
  78.     'maintain proper tabstop index
  79.     If i% >= TabStops(t%) Then
  80.         If t% < (NumTabStops - 1) Then
  81.         t% = t% + 1
  82.         End If
  83.     End If
  84.     Wend
  85.     TheLine = NewLine$
  86.     DoALine = True
  87. End Function
  88.  
  89.